<template>
  <div>
    <el-dialog title="新增用户" :visible.sync="thistype" @close="fun(tname)">
      <el-form label-width="80px" :model="form" ref="form">
        <el-form-item label="用户昵称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="入学状态">
            <el-select v-model="form.school" placeholder="请选择">
                <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
            </el-select>
          <!-- <el-radio-group v-model="form.radio">
            <el-radio label="1">入学</el-radio>
            <el-radio label="2">未入学</el-radio>
          </el-radio-group> -->
        </el-form-item>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="thistype = false">取 消</el-button>
        <el-button type="primary" @click="upuser">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

export default {
  props: ['type', 'fun', 'tname'],
  data () {
    return {
      thistype: this.type, // 模态框状态，
      form: {
        name: '', // 用户名称
        school: '' // 入学状态的单选按钮
      },
      formtype: '',
      options: [{
        value: '入学',
        label: '入学'
      }, {
        value: '未入学',
        label: '未入学'
      }]
    }
  },
  methods: {
    // 新增，判断用户信息是否填写完整
    upuser () {
    //   this.thistype = true
      var type = true
      for (var i in this.form) {
        if (this.form[i] === '') {
          type = false
        }
      }

      if (type) {
        this.thistype = false
        console.log('子组件' + this.form.name + this.form.school)
        this.$emit('func', this.form)
        // this.form = ''
        // 请求接口并传递数据
        // console.log(arrnew)
        // console.log(this.form.name, this.form.school)

        // this.form = ''
        // for (var j in this.form) {
        // //   console.log(this.form[j] instanceof Object)
        //   this.form[j] = ''
        // }
      } else {
        this.thistype = true
        this.$message.error('请补全信息')
      }
    }
  },
  watch: {
    // 监听模态框的状态
    type () {
      this.thistype = this.type
    },
    form () {
      var json = {}
      for (var i in this.form) {
        // this.tablerow[i] = this.tablerow[i].toString()
        this.$set(json, i, this.form[i].toString())
      }
      this.form = json
    }
  }
}
</script>

<style>
</style>

<!-- <template>
  <div>
    <el-dialog title="新增用户" :visible.sync="thistype" @close="fun(tname)">
      <div slot="footer" class="dialog-footer">
        <el-form label-width="80px" :model="formInline" ref="form">
          <el-form-item label="用户昵称">
            <el-input v-model="formInline.user"></el-input>
          </el-form-item>
          <el-form-item label="入学状态" >
            <el-select v-model="formInline.region" placeholder="">
              <el-option label="入学" value="1"></el-option>
              <el-option label="未入学" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>

        <el-button @click="thistype = false">取 消</el-button>
        <el-button type="primary" @click="upuser">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    props: ['type', 'fun', 'tname'],
    data() {
      return {
        thistype: this.type, //模态框状态，
        formInline: {
          user: '',
          region: ''
        }
      }
    },
    methods: {
      //判断用户信息是否填写完整
      upuser() {
        var type = false
        for (var i in this.form) {
          if (this.form[i] == '') {
            type = true
          }
        }
        if (type) {
          // 请求接口并传递数据
        } else {
          // console.log('111');
          this.$message.error('请补全信息')
        }
      }
    },
    watch: {
      //监听模态框的状态
      type() {
        this.thistype = this.type
      }
    }
  }
</script>

<style>
</style>
 -->
